<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Wuser extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('wuser',array('engine'=>'INnoDB'));
        $table->addColumn('nickname', 'string',array('limit' => 50,'comment'=>'昵称'))
            ->addColumn('openid', 'string',array('limit' => 50,'comment'=>'openid'))
            ->addColumn('sex', 'integer',array('limit' => 1,'default'=>0,'comment'=>'性别1男2女0未知'))
            ->addColumn('city', 'string',array('limit' => 20,'default'=>'','comment'=>'城市'))
            ->addColumn('country', 'string',array('limit' => 20,'default'=>'','comment'=>'国家'))
            ->addColumn('province', 'string',array('limit' => 20,'default'=>'','comment'=>'省份'))
            ->addColumn('headimgurl', 'string',array('limit' => 200,'default'=>'','comment'=>'头像'))
            ->addColumn('subscribe', 'integer',array('limit' => 1,'default'=>1,'comment'=>'关注状态'))
            ->addColumn('subscribe_time', 'integer',array('limit' => 10,'default'=>0,'comment'=>'关注时间'))
            ->addColumn('unionid', 'string',array('limit' => 50,'default'=>'','comment'=>'unionid'))
            ->addColumn('subscribe_scene', 'string',array('limit' => 20,'default'=>'','comment'=>'关注场景'))
            ->addColumn('add_time', 'datetime',array('default'=>'CURRENT_TIMESTAMP','comment'=>'添加时间'))
            ->addColumn('update_time', 'datetime',array('default'=>'CURRENT_TIMESTAMP','comment'=>'更新时间'))
            ->addColumn('acc_time', 'integer',array('limit' => 10,'default'=>0,'comment'=>'最后交互时间'))
            ->addColumn('wechat_id', 'string',array('limit' => 30,'comment'=>'微信id'))
            ->addIndex(array('openid'), array('unique' => true))
            ->addIndex(array('nickname'))
            ->addIndex(array('nickname','wechat_id'))
            ->addIndex(array('acc_time'))
            ->create();
    }
}
